package utils.push;

import com.alibaba.fastjson.JSONObject;
import entity.ConfigFile;
import utils.json.InitConfig;
import utils.okhttp.OkHttpUtil;

/**
 * PushPlus推送工具类
 */
public class PushUtil {
    private static final ConfigFile configFile = InitConfig.getInstance().getConfig();
    private static final OkHttpUtil okHttpUtil = OkHttpUtil.getInstance();
    private static String token;

    private PushUtil() {
        if (InitConfig.isEnablePush()) {
            token = configFile.getPush().getPushPlusToken();
        }
    }

    private static final PushUtil instance = new PushUtil();

    public static PushUtil getInstance() {
        return instance;
    }

    public int PushPlus(String title, String json) {
        String url = "http://www.pushplus.plus/send";
        JSONObject post = new JSONObject();
        post.put("token", token);
        post.put("title", title);
        post.put("content", json);
        post.put("template", "json");
        return okHttpUtil.PushPlusPost(url, post.toJSONString());
    }
}
